#ifndef __TRACER_H__
#define __TRACER_H__
#include <iostream>

using namespace std;

#define TRACER_DEFAULT_BUFF_SIZE 128

template <typename T, int buff_size = TRACER_DEFAULT_BUFF_SIZE>
class Tracer
{
    protected:
        T ring_buff[buff_size];
        int num;
        const char *tracer_name;
    public:
        Tracer(const char *name)
        {
            tracer_name = name;
        }
        virtual string toString(T &value) = 0;
        void save(T &value)
        {
            int save_index = num%buff_size; 
            ring_buff[save_index] = value;        
            num++;
        }
        void print()
        {
            cout << tracer_name << endl;
            int index = 0;
            int print_num = num;
            if(num > buff_size){
                index = (num)%buff_size;
                print_num = buff_size;
            }
            for (int i = 0; i < print_num - 1; i++)
            {
                cout << '\t' << toString(ring_buff[index]) << endl;
                index = (index+1)%buff_size;
            }
            cout << "==>\t" << toString(ring_buff[index]) << endl;
            
        }
        

};



#endif